package com.example.friend.service.impl;


import com.example.core.domain.PageDomain;
import com.example.core.domain.TableDataInfo;
import com.example.friend.domain.vo.UserMessageVO;
import com.example.friend.manger.MessageCacheManager;
import com.example.friend.mapper.MessageMapper;
import com.example.friend.service.IUserMessageService;
import com.example.scurity.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserMessageServiceImpl implements IUserMessageService {

    @Autowired
    private MessageCacheManager messageCacheManager;

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public TableDataInfo selectUserMessageList(PageDomain page) {
        //分页参数
        int start = (page.getPageNum() - 1) * page.getPageSize();
        int end = start + page.getPageSize();
        return messageCacheManager.selectUserMessageList(SecurityUtils.getUserId(), start, end);
    }

    @Override
    public UserMessageVO detail(Long messageId, Long textId) {
        return messageCacheManager.detail(messageId, textId);
    }

    @Override
    public int delete(Long messageId) {
        //先删缓存 再删数据库
        messageCacheManager.delete(SecurityUtils.getUserId(), messageId);
        return messageMapper.deleteById(messageId);
    }
}
